<?php
class MobileUrlParser
{
    public static function getUrlType($url)
    {
        $result = array('type' => 'direct', 'video_id' => '', 'error' => '', 'new_url' => $url);
		
		if(strpos($url, 'youtube') !== false)
		{
			$result['type'] = 'youtube';
			//check embed source if this video from youtube server
			if(strpos($url, 'embed') === false)
			{
				//Url format not for Youtube embed object
				$embed_format = "http://youtube.com/embed/%s?api=postMessage&amp;info=false&amp;autoPlay=1&amp;logo=0&amp;autoplay=1&amp;cc_load_policy=1";
				$output = parse_url($url); //Parse format url
				if(!empty($output) && !empty($output['query']))
				{
					//Parse query string
					parse_str($output['query'], $query);
					if(!empty($query) && !empty($query['v']))
					{
						//Build new query
						$new_url = sprintf($embed_format, $query['v']);
						$result['new_url'] = $new_url;
					}
				}
			}
		}
		else if(strpos($url, 'dailymotion') !== false)
		{
			$result['type'] = 'daily';
		}
		return $result;
	}
}